package wc.phrase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import wc.parserUtil.ParserWords;

public class Phrases {

	private HashMap<Map.Entry<String, String>, Integer> _phrases = new HashMap<Map.Entry<String, String>, Integer>();
	private ParserWords _parserWords;
	
	public Phrases(ParserWords parserWords) {
		_parserWords = parserWords;
	}
	
	public void parseSentence(String sentence) {
		_parserWords.parseLine(sentence, true);
		
		List<String> words = _parserWords.getItems();
		
		for(int i = 0; i < words.size() - 1; i++) {
			for(int j = i; j < words.size(); j++) {
				Map<String, String> twoPhrase = new HashMap<String, String>();
				twoPhrase.put(words.get(i), words.get(j));
				twoPhrase.put(words.get(j), words.get(i));
				Set<Map.Entry<String, String>> phraseSet = twoPhrase.entrySet();
				
				int iid = 0;
				for(Map.Entry<String, String> phrase : phraseSet) {
					if(_phrases.containsKey(phrase)) {
						int countFrequency = _phrases.get(phrase);
						_phrases.put(phrase, countFrequency + 1);
					} else {
						if(iid == 1) {
							_phrases.put(phrase, 1);
						} else {
							iid++;
						}
					}
				}
			}
		}
	}
	
	public HashMap<Map.Entry<String, String>, Integer> getPhrases() {
		return _phrases;
	}
	
}
